﻿using System.Windows;
using DSPL.Services;
using DSPL.Contracts;
using DSPL.Common;
using System.Data;
using DSPL.Services.Services;
using DSPL.Contracts.Common;
using DSPL.Contracts.ViewModel;
using DSPL.Contracts.Command;
using DSPL.Finac.Common;

namespace DSPL.Finac.ViewModel
{
    public class ProductTypeMasterViewModel : BaseViewModel
    {
        private bool isTypeCodeFocused;
        private bool isTypeNameFocused;

        #region Define properties

        public bool IsTypeCodeFocused
        {
            get { return isTypeCodeFocused; }
            set
            {
                isTypeCodeFocused = value;
                this.OnPropertyChanged("IsTypeCodeFocused");
            }
        }

        public bool IsTypeNameFocused
        {
            get { return isTypeNameFocused; }
            set
            {
                isTypeNameFocused = value;
                this.OnPropertyChanged("IsTypeNameFocused");

            }
        }
        #endregion


        #region Constructor

        public ProductTypeMasterViewModel()
            : base()
        {
            MessageTitle =  "Product Type Master";
        }

        #endregion
        /// <summary>
        /// Validate mandatory data before save
        /// </summary>
        /// <param name="obj"></param>
        protected override void PreDataValidateExecuted(object obj)
        {
            IsTypeCodeFocused = false;
            IsTypeNameFocused = false;

            var messageService = new MessageService();
            if (CurrentRow["TypeCode"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.ProductTypeCodeNotEmpty, MessageTitle,MessageType.InfoOK);
                IsTypeCodeFocused = true;
                this.IsValid = false;
                return;
            }

            if (CurrentRow["TypeName"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.ProductTypeNameNotEmpty,MessageTitle, MessageType.InfoOK);
                IsTypeNameFocused = true;
                this.IsValid = false;
                return;
            }
            this.IsValid = true;
        }
    }
}